//
//  NgCollectionHeadView.m
//  NgTopOSShove
//
//  Created by yscompany on 2018/11/27.
//  Copyright © 2018 NgTopOS. All rights reserved.
//

#import "NgCollectionHeadView.h"
#import "SDCycleScrollView.h"


@interface NgCollectionHeadView ()<SDCycleScrollViewDelegate>

@property (nonatomic, assign) NgCollectionType type;
@property (nonatomic, strong) SDCycleScrollView *scrollView; //广告轮播
@property (nonatomic, strong) UIView *btnInfoView;//按钮背景
@property (nonatomic, strong) NSArray *imgUrlArray; //NgCollectionTypeSliderCarousel 状态下需要url
@property (nonatomic, strong) NSArray *infoDictArray; // NgCollectionTypeSliderCarousel 模式下传入的infoDict 内含imgurl 以及点击事件响应的url
@end

@implementation NgCollectionHeadView

- (instancetype)initWithFrame:(CGRect)frame collectionType:(NgCollectionType)type infoDictArray:(nonnull NSArray *)infoDictArray{
    if (self = [super initWithFrame:frame]) {
        self.type = type;
        self.infoDictArray = infoDictArray;
        [self setSubviews];
    }
    return self;
}
- (instancetype)init {
    if (self = [super init]) {
        [self setSubviews];
    }
    return self;
}
- (void)setSubviews {
    [self addSubview:self.scrollView];
}

#pragma mark - getter method
- (SDCycleScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenW, 120) delegate:self placeholderImage:[UIImage imageNamed:@"tabbar_picture"]];
        _scrollView.imageURLStringsGroup = self.imgUrlArray;
    }
    return _scrollView;
}
- (NSArray *)imgUrlArray {
    if (!_imgUrlArray) {
        NSMutableArray * tempArray = [NSMutableArray array];
        [self.infoDictArray enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            [tempArray addObject:[HDVerfiyTools getSafeString:[obj objectForKey:@"imgUrl"]]];
        }];
        _imgUrlArray = tempArray;
    }
    return _imgUrlArray;
}
@end
